#ifndef __MYIIC_H
#define __MYIIC_H

#include "main.h"
#include "delay.h"

#include "FreeRTOS.h"
#include "task.h"

typedef struct iic_bus{
	GPIO_TypeDef* IIC_SDA_PORT;
	GPIO_TypeDef* IIC_SCL_PORT;
	u16 IIC_SDA_PIN;
	u16 IIC_SCL_PIN;
}iic_bus_struct;


void SDA_Input_Mode(iic_bus_struct* bus);
void SDA_Output_Mode(iic_bus_struct* bus);

void SDA_Output(iic_bus_struct* bus, u16 value);
void SCL_Output(iic_bus_struct* bus, u16 value);
u8 SDA_Input(iic_bus_struct* bus);

void myiic_start(iic_bus_struct* bus);
void myiic_stop(iic_bus_struct* bus);
void myiic_sendack(iic_bus_struct* bus);
void myiic_sendnack(iic_bus_struct* bus);
u8 myiic_waitack(iic_bus_struct* bus);
void myiic_sendbyte(iic_bus_struct* bus, u8 data);
u8 myiic_readbyte(iic_bus_struct* bus);


u8 myiic_send_one_byte(iic_bus_struct* bus, u8 addr, u8 reg, u8 data);
u8 myiic_send_bytes(iic_bus_struct* bus, u8 devaddr, u8 reg, u8* data, u8 len);
u8 myiic_read_one_byte(iic_bus_struct* bus, u8 devaddr, u8 reg);
u8 myiic_read_bytes(iic_bus_struct* bus, u8 devaddr, u8 reg, u8* data, u8 len);

void iic_dev_init(iic_bus_struct* bus);

#endif
